package com.ruoyi.web.controller.community.notice;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.ruoyi.community.domain.BaseNotice;
import com.ruoyi.community.domain.SimpleNoticeContent;
import com.ruoyi.community.service.IBaseNoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 公告Controller
 *
 * @author ruoyi
 * @date 2021-12-21
 */
@RestController
@RequestMapping("/community/notice")
public class NoticeController extends BaseController
{
    @Autowired
    private IBaseNoticeService baseNoticeService;


    /**
     * 查询社区公告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BaseNotice baseNotice)
    {
        startPage();
        List<BaseNotice> list = baseNoticeService.selectBaseNoticeList(baseNotice);
        return getDataTable(list);
    }

    /**
     * 查询社区公告缩略信息列表（除党建与业委会公告以外）,不含图片，为管理端预览列表服务
     */
    @GetMapping("/preview_for_web")
    public TableDataInfo preview_for_web(BaseNotice baseNotice)
    {
        startPage();
        List<BaseNotice> list = baseNoticeService.selectCommunityNoticePreviewWithoutPic(baseNotice);
        return getDataTable(list);
    }

    /**
     * 查询社区公告缩略信息列表（除党建与业委会公告以外）,含图片，为小程序端预览服务
     */
    @GetMapping("/preview_for_app")
//    public TableDataInfo preview_for_app(BaseNotice baseNotice)
//    {
//        startPage();
//        List<BaseNotice> list = baseNoticeService.selectCommunityNoticePreviewWithPic(baseNotice);
//        return getDataTable(list);
//    }
    public AjaxResult preview_for_app(BaseNotice baseNotice)
    {
//        startPage();
        List<BaseNotice> list = baseNoticeService.selectCommunityNoticePreviewWithPic(baseNotice);
//        return getDataTable(list);
        return AjaxResult.success(list);
    }

    /**
     * 获取公告详细信息
     */
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") String noticeId)
    {
        return AjaxResult.success(baseNoticeService.selectBaseNoticeById(noticeId));
    }

    /**
     * 新增公告列表
     */
    @Log(title = "公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseNotice baseNotice)
    {
        return toAjax(baseNoticeService.insertBaseNotice(baseNotice));
    }

    /**
     * 修改公告
     */
    @Log(title = "公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseNotice baseNotice)
    {
        return toAjax(baseNoticeService.updateBaseNotice(baseNotice));
    }

    /**
     * 删除公告
     */
    @Log(title = "公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable String[] noticeIds)
    {
        return toAjax(baseNoticeService.deleteBaseNoticeByIds(noticeIds));
    }
}
